/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ClientStartGame.java
 *
 * Created on Dec 22, 2010, 11:06:37 PM
 */

package run;

/**
 *
 * @author Toan
 */
import java.net.*;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;


public class ClientStartGame extends javax.swing.JFrame {
    private Socket socket = null;
    private MyInfo info = null;
    private String answer = null;
    
    public ClientStartGame(MyInfo _info, Socket _socket) {
        info = _info;
        socket = _socket;
        initComponents();
        this.setLocation(300, 300);
        this.setVisible(true);
        jLabelUserName.setText(info.getUsername());
        jLabelYourMark.setText(Integer.toString(info.getMark()));
        this.setResizable(false);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    public void  setMark(String msg){
        jLabelYourMark.setText(msg);
    }
    /** Creates new form ClientStartGame */
    public ClientStartGame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Answer = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabelUserName = new javax.swing.JLabel();
        jLabelYourMark = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel2.setForeground(new java.awt.Color(255, 0, 51));
        jLabel2.setText("Trả lời :");

        jButton1.setText("SEND");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabelUserName.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        jLabelUserName.setForeground(new java.awt.Color(0, 51, 204));
        jLabelUserName.setText("User Name");

        jLabelYourMark.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        jLabelYourMark.setForeground(new java.awt.Color(255, 51, 51));
        jLabelYourMark.setText("Your mark");

        jLabel1.setText("Đội chơi :");

        jLabel3.setText("Điểm số :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(77, 77, 77)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabelYourMark, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(Answer, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(129, 129, 129)
                .addComponent(jButton1)
                .addContainerGap(118, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jLabelYourMark, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Answer, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addGap(28, 28, 28))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        try {
            // TODO add your handling code here:
            // gui dap an den server
            answer = Answer.getText();
            DataOutputStream outToServer = new DataOutputStream(socket.getOutputStream());
            outToServer.writeBytes(answer+'\n');
            outToServer.flush();
            System.out.println("Send to Server :"+answer);
            Answer.setText("");
        /*    if (info.getUsername().equals(ServerScreen.getName1()))
            ServerScreen.setAnswer1(answer);
            else if (info.getUsername().equals(ServerScreen.getName2()))
             ServerScreen.setAnswer2(answer);
            else if (info.getUsername().equals(ServerScreen.getName3()))
             ServerScreen.setAnswer3(answer);
            else if (info.getUsername().equals(ServerScreen.getName4()))
             ServerScreen.setAnswer4(answer);
        */
         } catch (IOException ex) {
            Logger.getLogger(ClientStartGame.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        /* Lay Text
         * Client.sendAnswer(text);
         */
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ClientStartGame().setVisible(true);
            }
        });
    }
    
    public void setTextMark(int mark){
        jLabelYourMark.setText(Integer.toString(mark));
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Answer;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelUserName;
    private javax.swing.JLabel jLabelYourMark;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables

}
